function build_volume, vol_size, data3d, mind, maxd, vol=volume_in

	if(NOT(keyword_set(volume_in))) then begin
		vol = ulonarr(vol_size, vol_size, vol_size)
	endif else begin
		vol = volume_in
	endelse


	num_points = n_elements(data3d) / 3

	;scale data3d to fit voxels

	maxMin = maxd - mind

	;find greatest range!
	;maxMin[0:1] = max(maxMin[0:1])

	scale = ((((data3d - rebin(mind, 3, num_points)) / (rebin(maxMin, 3, num_points)))) < 1.0) * rebin(vol_size - 1, 3, num_points)

	vol[scale[0,*], scale[1,*], scale[2,*]]++

	return, vol
end